<template>
  <!-- 招标候选人公示 -->
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="标段">
              <a-input placeholder="请选择标段" v-model="queryParam.bidSectionId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="公示标题">
              <a-input placeholder="请输入公示标题" v-model="queryParam.publicityName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button @click="handleAdd" type="primary" icon="plus" style="margin-left: 8px">新增</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <template v-if="publicityType == 4 || publicityType ==5">
          <a-divider type="vertical" />
<!--          <a @click="handleSetHxr(record)" v-if="publicityType ==4">设置候选人</a>-->
          <a @click="handleSetZbr(record)" v-if="publicityType ==5">设置中标候选人</a>
          </template>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <ex-tender-candidate-announce-modal ref="modalForm" @ok="modalFormOk" :projectId="projectId" :publicityType="publicityType"></ex-tender-candidate-announce-modal>
    <zbhxr-modal ref="zbhxrModalRef"></zbhxr-modal>
    <set-zbr-modal ref="setZbrModalRef"></set-zbr-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ExTenderCandidateAnnounceModal from './modules/ExTenderCandidateAnnounceModal'
import ZbhxrModal from '@/views/exProjectInfo/Zbhxr'
import SetZbrModal from '@/views/exTender/SetZbr'

export default {
  name: 'ExTenderCandidateAnnounceList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ExTenderCandidateAnnounceModal,
    ZbhxrModal,
    SetZbrModal
  },
  props: { 
    projectId: {},
    publicityType:{},//公示类型 
  },
  data() {
    return {
      description: '中标候选人公示管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '标段',
          align: 'center',
          dataIndex: 'bidSectionName',
        },
        {
          title: '标题',
          align: 'center',
          dataIndex: 'publicityName',
        }, 
        {
          title: '类型',
          align: 'center',
          dataIndex: 'publicityType_dictText', 
        },
        {
          title: '开始时间',
          align: 'center',
          dataIndex: 'publicityStartTime',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '结束时间',
          align: 'center',
          dataIndex: 'publicityEndTime',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '附件',
          align: 'center',
          dataIndex: 'attachmentCode',
          scopedSlots: { customRender: 'fileSlot' },
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status_dictText',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/exTender/exTenderCandidateAnnounce/list',
        delete: '/exTender/exTenderCandidateAnnounce/delete',
        deleteBatch: '/exTender/exTenderCandidateAnnounce/deleteBatch',
        exportXlsUrl: '/exTender/exTenderCandidateAnnounce/exportXls',
        importExcelUrl: 'exTender/exTenderCandidateAnnounce/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  watch: {
    projectId: {
      immediate: true,
      handler(val) {
        this.getProjectDetail()
      },
    },
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'bidSectionId', text: '标段（包）标识码', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'publicityId',
        text: '候选人公示标识码 - 交易系统中使用或生成的唯一码,数据交换时新增或修改的依据',
        dictCode: '',
      })
      fieldList.push({ type: 'string', value: 'publicityName', text: '公示标题 - 自由文本', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'publicityContent',
        text: '公示内容 - 多个中标候选人一并显示',
        dictCode: '',
      })
      fieldList.push({ type: 'string', value: 'noticeMedia', text: '公示发布媒体 - 多个以半角分号分割', dictCode: '' })
      fieldList.push({ type: 'string', value: 'url', text: '公示源url - 交易平台中标候选人公示的url', dictCode: '' })
      fieldList.push({ type: 'string', value: 'publicityType', text: '公示类型 - 参考b.9.6公示类型', dictCode: '' })
      fieldList.push({ type: 'date', value: 'publicityStartTime', text: '公示开始时间 - yyyymmddhhmmss' })
      fieldList.push({ type: 'date', value: 'publicityEndTime', text: '公示结束时间 - yyyymmddhhmmss' })
      fieldList.push({ type: 'string', value: 'otherContent', text: '其他内容 - 自由文本', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'attachmentCode',
        text: '附件关联标识号 - 多个附件关联标识号以半角分号隔开',
        dictCode: '',
      })
      fieldList.push({ type: 'string', value: 'status', text: '状态(0-保存 1-送审 2-通过 3-驳回)', dictCode: '' })
      this.superFieldList = fieldList
    },
    getProjectDetail() {
      var that = this
      this.queryParam.projectId = that.projectId
      this.queryParam.publicityType = that.publicityType;
      this.loadData()
    },
    handleSetHxr(record){
      this.$refs.zbhxrModalRef.show(record);
    },
    handleSetZbr(record){
      this.$refs.setZbrModalRef.show(record);
    },
    searchReset() {
      this.queryParam = { projectId: this.projectId }
      this.loadData()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>